package com.bigflexlib.x.flash.events.subscriber
{
	
	
	
	/**
	 * 
	 * 
	 * 
	 * 
	 * 
	 * @author aldo.bucchi@gmail.com
	 * 
	 */	
	public class EventListenerSubscriber
	{
		
		
		
		/////////////////////////////////////////////////
		///////////////////// target ////////////////////
		/////////////////////////////////////////////////		

		private var _target:Object;
		
		public function get target( ):Object
		{
			return _target;
		}
		
		
		public function set target( v:Object ):void
		{
			if ( _target == v )
				return ;
			
			_target = v;

			refresh( );		
		}
		
		
		/////////////////////////////////////////////////
		////////////////////// config ///////////////////
		/////////////////////////////////////////////////		
		
		
		private var _config:Array;
		
		/**
		 * 
		 * A two dimensional array containing event listener configuration.
		 * ( more on this... )
		 * 
		 * @return 
		 * 
		 */		
		public function get config( ):Array
		{
			return _config;
		}
		
		
		public function set config( v:Array ):void
		{
			if ( _config == v )
				return ;
			
			_config = v;
			
			refresh( );
		}
		
		
		
		
		

		private var steps:Array = [];	

		
		
		
		
		private function refresh( ):void
		{
		
			// remove current steps ( if any )
			for each ( var step:EventSubscriptionStep in steps )
			{
				step.kill( );
			}
			
			steps = new Array( );
		
		
			// if we have a target and config, set new subscription steps
			if ( _target && _config )
			{
				for each ( var conf:Array in _config )
				{
					steps.push( new EventSubscriptionStep( _target, conf ) );
				}
			}		
		
		
		}
		
				

		
	}
	

}



